/**
 * Created by hcadmin on 16/10/17.
 */
$(function(){
    var url_getData = apiurl+"/approvals/temp/list";
    var data = {
        listType:"1",
        group_id:localStorage.group_id,
        approval_status:"-1"
    };
    $.ajax({
        url:url_getData,
        async:false,
        data:data,
        success:function(d){
           var data = JSON.parse(d).data;
            for(var i=0;i<data.length;i++){
                var approval_status     = data[i].approval_status;
                var approval_icon       = data[i].approval_icon;
                var approval_title      = data[i].approval_title;
                var approval_temp_id    = data[i].approval_temp_id;
                //var group_id            = data[i].group_id;

                if(approval_status=="1"){
                    $("#had_text").show();
                    $(".had_used").append(
                        "<div class='model_cell_big'>" +
                            "<div class='model_cell_mid'>" +
                                //"<div class='col-xs-8'>" +
                                    "<img src='"+approval_icon+"' class='model_cover'>" +
                                    "<span class='model_name'>"+approval_title+"</span>" +
                                //"</div>" +
                                //"<div class='col-xs-4'>" +
                                    "<img src='../approvalImg/Giab/hadAdd.png' id='"+approval_temp_id+"' status='"+approval_status+"' group_id = '"+group_id+"' class='model_use_state'>" +
                                //"</div>" +
                            "</div>" +
                        "</div>"
                    );
                }else{
                    $("#un_text").show();
                    $(".un_used").append(
                        "<div class='model_cell_big'>" +
                            "<div class='model_cell_mid'>" +
                                //"<div class='col-xs-8'>" +
                                    "<img src='"+approval_icon+"' class='model_cover'>" +
                                    "<span class='model_name'>"+approval_title+"</span>" +
                                //"</div>" +
                                //"<div class='col-xs-4'>" +
                                    "<img src='../../log/logImg/add.png' id='"+approval_temp_id+"' status='"+approval_status+"' group_id = '"+group_id+"' class='model_use_state'>" +
                                "</div>" +
                            //"</div>" +
                        "</div>");
                }
            }
        }
    });

    //启/停用模板
    $(document).on('click','.model_use_state',function(){
        var approval_temp_id = $(this).attr("id");
        var status= $(this).attr("status");
        var new_status;
        if(status=="0"){
            new_status = "1";
        }else{
            new_status = "0";
        }
        //var group_id = $(this).attr("group_id");
        var url_putData = apiurl+"/approvals/temp/"+approval_temp_id+"";
        var data = {
            new_status:new_status,
            group_id  :localStorage.group_id
        };
        $.ajax({
            type:"PUT",
            url :url_putData,
            data:data,
            success:function(d){
                window.location.href = "approvalAdministration.html";
            }
        })
    })
});
